<%@ page language="java" contentType="text/html; charset=UTF-8"%>

<!DOCTYPE html>
<html>
	<head>
		<title>商城后台_分类管理</title>
		<%@include file="../header.jsp" %>
		<style>
			body{padding-top: 70px;}
			._category{width: 50px;height: 25px;border: 1px solid #DDDDDD;border-radius: 5px;text-align: center;line-height: 25px;}
			._category_add{width: 100px;height: 25px;line-height: 25px;margin-top: 3px;}
			
			._addgood{background-color: white;border: 1px solid #cccccc;border-radius: 3px;margin-top: 27px;height: 28px;}
		</style>
	</head>
	<body>
		<%@include file="top.jsp" %>
		
		<div class="container">
			
				<div class="row">
					<div class="span4">
						<p>一级分类</p>
						<select id="_pcategory" onchange="doshowcategory()">
							<option>请选择一项</option>
							<option value="clothes01">衣服</option>
							<option value="digital01">数码</option>
							<option value="shoes01">鞋子</option>
						</select>
					</div>
					<div class="span4">
						<p>二级分类</p>
						<select id="_category" onchange="doshowgood()">
							<option>请选择一项</option>
						</select>
					</div>
					<div class="span3">
						<button class="_addgood" onclick="doaddgood()">增加商品</button>
					</div>
				</div>
				
				<div class="row">
					<div class="span1"><p>商品列表</p></div>
					<div class="span12">
						<table class="table table-bordered table-condensed">
	 						<thead>
	 							<tr>
	 								<td>#</td>
	 								<td style="text-align: center;">名称</td>
	 								<td>售价</td>
	 								<td>产地</td>
	 								<td>描述信息</td>
	 							</tr>
	 						</thead>
	 						<tbody id="datagood">
	 						
	 						</tbody>
						</table>
					</div>
				</div>
			</div>
			
		
		<script>
			$('.dropdown-toggle').dropdown();

			function addCategory(id){
				window.location ="${basePath}admin/admin_toAddCategoryUI.action?pcategory.id="+id;				
			}
			function deleteCategory(id){
				window.location ="${basePath}admin/admin_deleteCategory.action?category.id="+id;				
			}
			//异步获取二级分类
			function doshowcategory(){
				var pc = $('#_pcategory option:selected').val();
				if(pc != '请选择一项'){
					$.ajax({
						url:"${basePath}admin/admin_ajaxgetCategory.action",
						data:{"pcategory.id":pc},
						type:"POST",
						dataType:"json",
						success:function(data){
							var c = $('#_category');
							c.empty();
							c.append('<option>请选择一项</option>');
							for(var i = 0; i<data.categorylist.length;i++){
								c.append('<option value="'+data.categorylist[i].id+'" >'+data.categorylist[i].name+'</option>');
							}
						},
						error: function(){alert("false");
						}
					});
				}else{
					var c = $('#_category');
					c.empty();
					c.append('<option>请选择一项</option>');
				}
			}
			//异步获取商品
			function doshowgood(){
				var cid = $('#_category option:selected').val();
				if(cid != '请选择一项'){
					$.ajax({
						url:"${basePath}admin/admin_ajaxgetGood.action",
						data:{"category.id":cid},
						type:"POST",
						dataType:"json",
						success:function(data){
							var datas = $('#datagood');
							datas.empty();
							$.each(data.goodlist,function(i,v){
								var tr = $('<tr id="'+v.id+'" ></tr>');
								tr.dblclick(function(){ 
									window.location = "${basePath}admin/admin_toDetailUI.action?good.id="+v.id;	
								});
								
								tr.append('<td>'+(i+1)+'</td');
								tr.append('<td>'+v.name+'</td>');
								tr.append('<td>'+v.price+'</td>');
								tr.append('<td>'+v.place+'</td>');
								tr.append('<td>'+v.description+'</td>');
								datas.append(tr);

							});
						},
						error: function(){alert("false");
						}
					});
				}
			}
			//增加商品
			function doaddgood(){
				window.location = "${basePath}admin/admin_toAddGoodUI.action";
			}

			//跳转到商品详细页面
			function dodetail(id){
				alert(id);
				
				//window.location = "${basePath}admin/admin_toDetailUI.action?good.id="+id;				
			}
		</script>
	</body>
</html>
